package com.ruoyi.house_sale.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.house_sale.domain.PaidType;
import com.ruoyi.house_sale.domain.ProjectInfo;
import com.ruoyi.house_sale.service.IPaidTypeService;
import com.ruoyi.house_sale.service.IProjectInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.house_sale.domain.PaidScheme;
import com.ruoyi.house_sale.service.IPaidSchemeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 付款方案Controller
 *
 * @author ruoyi
 * @date 2022-03-28
 */
@RestController
@RequestMapping("/house_sale/PaidScheme")
public class PaidSchemeController extends BaseController
{
    @Autowired
    private IPaidSchemeService paidSchemeService;
//    @Autowired
//    private IPaidTypeService paidTypeService;
    @Autowired
    private IProjectInfoService projectInfoService;
    /**
     * 查询付款方案列表
     */
    @PreAuthorize("@ss.hasPermi('house_sale:PaidScheme:list')")
    @GetMapping("/list")
    public Map list(PaidScheme paidScheme)

    {

        Map map=new HashMap<>();
        startPage();
        List<Map> list = paidSchemeService.selectPaidSchemeList(null);
        System.err.println(list);
        map.put("paidSchemeList",list);
//        List<PaidType> list1= paidTypeService.selectPaidTypeList(null);
//        map.put("paidTypeList",list1);
        List<ProjectInfo> list2 = projectInfoService.selectProjectInfoList(null);
        map.put("projectInfoList",list2);
        return map;
    }

    /**
     * 导出付款方案列表
     */
//    @PreAuthorize("@ss.hasPermi('house_sale:PaidScheme:export')")
//    @Log(title = "付款方案", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, PaidScheme paidScheme)
//    {
//        List<Map> list = paidSchemeService.selectPaidSchemeList(paidScheme);
//        ExcelUtil<PaidScheme> util = new ExcelUtil<PaidScheme>(PaidScheme.class);
//        util.exportExcel(response, list, "付款方案数据");
//    }

    /**
     * 获取付款方案详细信息
     */
    @PreAuthorize("@ss.hasPermi('house_sale:PaidScheme:query')")
    @GetMapping(value = "/{psid}")
    public AjaxResult getInfo(@PathVariable("psid") Long psid)
    {
        return AjaxResult.success(paidSchemeService.selectPaidSchemeByPsid(psid));
    }

    /**
     * 新增付款方案
     */
    @PreAuthorize("@ss.hasPermi('house_sale:PaidScheme:add')")
    @Log(title = "付款方案", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PaidScheme paidScheme)
    {
        return toAjax(paidSchemeService.insertPaidScheme(paidScheme));
    }

    /**
     * 修改付款方案
     */
    @PreAuthorize("@ss.hasPermi('house_sale:PaidScheme:edit')")
    @Log(title = "付款方案", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PaidScheme paidScheme)
    {
        return toAjax(paidSchemeService.updatePaidScheme(paidScheme));
    }

    /**
     * 删除付款方案
     */
    @PreAuthorize("@ss.hasPermi('house_sale:PaidScheme:remove')")
    @Log(title = "付款方案", businessType = BusinessType.DELETE)
    @DeleteMapping("/{psids}")
    public AjaxResult remove(@PathVariable Long[] psids)
    {
        return toAjax(paidSchemeService.deletePaidSchemeByPsids(psids));
    }
}
